<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new sfTestFunctional(new sfBrowser());
Doctrine_Core::loadData(sfConfig::get('sf_test_dir').'/fixtures');
# The below should work because I put it in JobeetTestFunctional.class.php
// BELOW Should work but I use the direct Doctrine_Core call above because it does not work
# $browser->loadData();

$browser->
  get('/')->

  with('request')->begin()->
    isParameter('module', 'job')->
    isParameter('action', 'index')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    info(' 1.1 - Expired jobs are not listed')->
    checkElement('.jobs td.position:contains("expired")', false)->
  end()
;

$max = sfConfig::get('app_max_jobs_on_homepage');
$browser->info('1 - The homepage')->
    get('/')->
    info(sprintf(' 1.2 - Only %s jobs are listed for a category', $max))->
    with('response')->
    checkElement('.category_programming tr', $max)
;

$browser->info('1 - The homepage')->
    get('/')->
    info(' 1.3 - A category has a link to the category page only if too many jobs')->
    with('response')->begin()->
        checkElement('.category_design .more_jobs', false)->
        checkElement('.category_programming .more_jobs')->
    end()
;

$q = Doctrine_Query::create()
    ->select('j.*')
    ->from('JobeetJob j')
    ->leftJoin('j.JobeetCategory c')
    ->where('c.slug = ?', 'programming')
    ->andWhere('j.expires_at > ?', date('Y-m-d', time()))
    ->orderBy('j.created_at DESC');
$job = $q->fetchOne();
$browser->info('1 - The homepage')->
    get('/')->
    info(' 1.4 - Jobs are sorted by date')->
    with('response')->begin()->
        checkElement(sprintf('.category_programming tr:first a[href*="/%d/"]',
        $job->getId()))->
    end()
;